package com.toocms.jinjuhang.ui.mine.order.evaluate

import android.text.TextUtils
import androidx.databinding.ObservableField
import com.toocms.jinjuhang.data.ImageData
import com.toocms.tab.base.ItemViewModel
import com.toocms.tab.binding.command.BindingAction
import com.toocms.tab.binding.command.BindingCommand

class OrderEvaluateImageItemModel(
    viewModel: OrderEvaluateModel,
    val item: (ObservableField<ImageData>) = ObservableField(ImageData())
) : ItemViewModel<OrderEvaluateModel>(viewModel) {
    val itemClickBindingCommand = BindingCommand<BindingAction>(BindingAction {
        if (item.get()?.id.isNullOrEmpty()) {
            viewModel.selectImage()
        }
    })
    val deleteClickBindingCommand = BindingCommand<BindingAction>(BindingAction {
        if (!item.get()?.id.isNullOrEmpty()) {
            viewModel.imageItems -= this@OrderEvaluateImageItemModel
        }
        if (viewModel.imageItems.isEmpty() || !TextUtils.isEmpty(viewModel.imageItems[0].item.get()?.id)) {
            viewModel.imageItems.add(
                0,
                OrderEvaluateImageItemModel(viewModel, ObservableField(ImageData()))
            )
        }
    })
}